package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Auther: zhaoss
 * @Date: 2023/5/4 - 05 - 04 - 18:53
 * @Description: com.sky.controller.user
 * @version: 1.0
 */
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 新增购物车
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO dto){
        return shoppingCartService.add(dto);
    }

    /**
     * 查询购物车
     * @return
     */
    @GetMapping("/list")
    public Result getCar(){
        return shoppingCartService.getCar();
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    public Result deleteCar(){
        return shoppingCartService.deleteCar();
    }

    /**
     * 减少一个商品
     * @param dto
     * @return
     */
    @PostMapping("/sub")
    public Result subCar(@RequestBody ShoppingCartDTO dto){
        return shoppingCartService.subCar(dto);
    }
}
